package com.beer.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beer.model.BeerExpert;

/**
 * Servlet implementation class BeerSelect
 */
//@WebServlet("/BeerSelect")
public class BeerSelect extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BeerSelect() {
        super();
        // TODO Auto-generated constructor stub
    }
    
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		BeerExpert be = new BeerExpert();
		String c = request.getParameter("color");
//		response.setContentType("text/html");
		
//		PrintWriter p = response.getWriter();
		
//		p.write("Beer selection advice:<br>");
//		
//		p.write("<br>got beer color: "+c);
		
		List<String> beerBrands = be.getBrands(c);
		
		request.setAttribute("styles", beerBrands);
		RequestDispatcher view = request.getRequestDispatcher("result.jsp");
		view.forward(request, response);
		
		
//		for(String beer: beerBrands){
//			p.write("<br>"+beer);
//		}
	}

}
